// 封装ajax请求
var request = (url, data = {}, method = 'GET') => {
    return new Promise((resole, reject) => {
        wx.request({
            url: 'http://192.168.31.180:3000' + url,
            data,
            header: {
                'content-type': 'application/json',
                'cookie': wx.getStorageSync('cookies') ? wx.getStorageSync('cookies').find(item => item.indexOf('MUSIC_U=') != -1) : ''
            },
            method,
            dataType: 'json',
            responseType: 'text',
            success: (res) => {
                //查看是否为登录请求，是的话就存储cookie
                if (data.isLogin) {
                    wx.setStorageSync('cookies', res.cookies);
                }
                resole(res.data)
            },
            fail: (err) => {
                reject(err)
            }
        });
    })
}

export { request }